<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // var str = 'abc123def456ghi789op007ty158';
        // var res = str.replace('123','***');
        // console.log(res);
        // //abc***def456ghi789op007ty158
        // var res1 = str.replace(/\d{3}/,'***');
        // console.log(res1);
        // //abc***def456ghi789op007ty158
        // var res2 = str.replace(/\d{3}/g,'***');
        // console.log(res2);
        // //abc***def***ghi***op***ty***

        // var arr = ['枪支','弹药','发论功'];
        // var str = '枪支是不是很危险，弹药是不是很危险，发论功是不是很危险';
        // // /枪支|弹药|发论功/
        // var reg = new RegExp('('+arr.join('|')+')','g');
        // var res = str.replace(reg,'***')
        // console.log(res);

        // //***是不是很危险，***是不是很危险，***是不是很危险

        // var str = '枪支是不是很危险，弹药是不是很危险，发论功是不是很危险';
        // var r1 = str.search('危险');
        // console.log(r1); // 6

        // var reg = /l{2}/;
        // var str1 = 'hello world';
        // var r2 = str1.search(reg);
        // console.log(r2); // 2 

        var str1 = 'abc123def456ggg789yui101ddf808';
        var s1 = str1.match('123');
        console.log(s1); // ['123', index: 3, input: 'abc123def456ggg789yui101ddf808', groups: undefined]
        // 跟exec 效果一样 

        var reg = /\d{3}/;
        var s2 = str1.match(reg);
        console.log(s2);
        //['123', index: 3, input: 'abc123def456ggg789yui101ddf808', groups: undefined]
        // 跟exec 效果一样 

        var reg = /\d{3}/g;
        var s3 = str1.match(reg);
        console.log(s3);
        //['123', '456', '789', '101', '808']

    </script>
</body>
</html>